<?
//引入所有子系统信息
include_once("../../../common/model/extender_import.php");



//根据页面数量信息，筛选信息，创造url，供页码使用
include_once("script/set_url.php");







    //这里是设计上传文件的部分：包含图片和附件。视频也应该用这种形式上传
    //统一设置一下保存图片的路径
    $_uf['path']        = ROOT_PATH_ . "/uploadfiles/member/";


    //上传文件
    if (is_uploaded_file($_FILES['importfile']['tmp_name']))
    {
        $_uf['upfile']       = $_FILES['importfile'];
        $_info               = upload_file($_uf);
        //上传后的文件名$_info['name'];

    }
?>







<?
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel2007.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/Writer/Excel5.php';
require_once ROOT_PATH_.'/application/PHPExcel/PHPExcel/IOFactory.php';
?>



<?
date_default_timezone_set('Europe/London'); //设置时间

$inputFileName = $_uf['path'].$_info['name'];

//判断一下，文件是2007还是旧版的excel
if(strstr($_info['name'],".")==".xls")
{
    $inputFileType = 'Excel5';
}
else if(strstr($_info['name'],".")==".xlsx")
{
    $inputFileType = 'Excel2007';
}
else
{
    echo "请检查文件格式";
}


//$inputFileType = 'Excel5';    //这个是读
//$inputFileType = 'Excel2007';//这个是计xlsx的
//$inputFileName = 'sample.xls';





//echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
/*
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列
*/
$objWorksheet = $objPHPExcel->getActiveSheet();//取得总行数
$highestRow = $objWorksheet->getHighestRow();//取得总列数

//echo 'highestRow='.$highestRow;
//echo "<br>";
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
//echo 'highestColumnIndex='.$highestColumnIndex;
//echo "<br />";



$headtitle=array();
$result=array();

for ($row = 0;$row <= $highestRow;$row++)
{
    $strs=array();
    //注意highestColumnIndex的列数索引从0开始
    for ($col = 0;$col < $highestColumnIndex;$col++)
    {
        $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();

        $result[$row][$col]=$strs[$col];
    }


}



 //已经拥有数组，然后按照这个数组，去批量插入数据。


//这边检验数据
//看看学校，年级班级 是否一致

//按结构输出部门的树
$school_list=select_lines_all_items($table_prefix."department","nid desc","parent_id = 0","");

//循环，查找数据库中，parent_nid = 当前的 nid的值
foreach($school_list as $key=>$value){
    $school_list[$key][$value['name']]=select_lines_all_items($table_prefix."department","listorder desc,name asc,nid desc",
        "parent_id = '{$value['nid']}'","");

    //循环，$school_list[$key]['grade'] 的数据，查找数据库中，parent_nid = 当前的 nid的值，记录在class
    foreach($school_list[$key][$value['name']] as $k=>$v){
        $school_list[$key][$value['name']][$k][$v['name']]=select_lines_all_items($table_prefix."department",
            "listorder desc,name asc,nid desc","parent_id = '{$v['nid']}'","");
    }
}


//循环提取出数组，是 学校+年级=班级的结构
//把每一个班级学校的信息，提取成一条数据存入新的数组

foreach ($school_list as $key=>$value)
{
    foreach ($value[$value['name']] as $k=>$v)
    {
        foreach ($v[$v['name']] as $kk=>$vv)
        {
            $class_list[]=$value['name'].$v['name'].$vv['name'];
        }
    }
}






$authur=$_SESSION['username'];



$date=date("Y-m-d h:m:s");

//如果第一行有标题的话，i就设置从1算起。






for($i=2;$i<count($result);$i++)
{



    $result[$i][5]=gmdate('Y-m-d H:i:s', ($result[$i][5] - $d) * $t);


    //0序号,1科目名称,2姓名的nid,3教练,4身份证号码,5考试日期,6状态,7考试车型,8车牌


  //导入的人的名称
  $authur=$_SESSION['username'];


    if($result[$i][0]){
  $values="('$date','".$result[$i][0]."','".$examname."','".$result[$i][5]."','".$result[$i][6]."','".$employee_list[$result[$i][3]]."','".$result[$i][7]."','".$equipment_list[$result[$i][8]]."','".$authur."'),".$values;

;



}
}






?>